'use strict';

var gulp = require('gulp');
var wrench = require('wrench');
var conf = require('./gulp/conf');
var browserSync = require('./gulp/browserSync');

/**
 *  读取gulp文件夹内的文件并加载
 */
wrench.readdirSyncRecursive('./gulp').filter(function(file) {
  return (/\.(js|coffee)$/i).test(file);
}).map(function(file) {
  require('./gulp/' + file);
});

/**
 *  启动任务
 */
gulp.task('default', ['clean'], function() {
  gulp.start('build');
});

/**
 *  启动任务并监听
 */
gulp.task('m', ['clean'], function() {
  gulp.start('build', 'watch', function() {
    browserSync.browserSyncInit([conf.paths.dist]);
  });
});

/**
 *  测试
 */
gulp.task('test', ['clean'], function() {
  browserSync.browserSyncInit([conf.paths.dist]);
  gulp.start('test:task', 'watch');
});
